1316A - Grade Allocation - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

t=int(input())

for i in range(t):
    l=list(map(int,input().split()))
    y=list(map(int,input().split()))
    y=sum(y)
    if y<=l[1]:
        print(y)
    else:
        print(l[1])

C++ Code:

//Idk how it works but it works
//¯\_(ツ)_/¯

#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>

using namespace std;

#define int long long
#define ll long long
#define cy cout << "YES"
#define cn cout << "NO"
#define eb emplace_back
#define itn int
#define fro for
#define cotu cout
#define forn( i, n ) for( int i = 0; i < n; i++ )

void output(bool fl) {
    if(fl) cy;
    else cn;
    cout << endl;
}

bool isPalindrom (string s){
    bool fl = true;
    for(int i = 0; i < s.size() / 2; i++) {
        if(s[i] != s[s.size() - 1 - i]){
            fl = false;
            return fl;
        }
    }
    return fl;
}

int sumOfNumbers(int n) {
    int res = 0;
    while(n > 0) {
        res += n % 10;
        n = n / 10;
    }
    return res;
}

void solve () {
    int n, m;
    cin >> n >> m;
    int res = 0;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        res += x;
    }
    cout << min(m, res) << endl;
    return;
}

main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin.exceptions(ios::badbit | ios::failbit);
    setlocale( LC_ALL, "Ukr" );

    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢛⡛⠛⡛⠄⠝⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⣤⣦⠶⣷⣆⢀⡝⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢂⣽⠏⠄⠄⠄⠈⢻⣧⢨⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠡⣸⡏⠄⠄⠄⠄⠄⠄⢿⣇⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡿⠿⠿⠿⠿⠟⠛⠛⠛⠛⠛⠟⠻⢋⢼⡟⠄⠄⠄⠄⠄⠄⠄⢸⣯⢈⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⢰⣿⣿⣿⣿⣿⣿⣿⡿⠿⠛⠛⠉⠉⠉⠣⠄⠄⠄⠄⠄⠄⠄⣼⡧⠠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡘⢿⣿⣿⣍⡩⠙⠁⠄⠄⠄⠄⠄⠄⠄⠄⠈⢂⠄⠄⠄⠄⣰⣿⣞⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣦⡙⡿⠋⠄⠄⠄⡀⠤⠄⠤⠄⠄⠄⠄⠄⠄⡆⠄⠄⣼⡟⠤⢈⠑⡙⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⡿⠡⠁⠄⠄⠄⡌⣰⣾⣿⣷⡄⢢⠄⠄⠄⠄⢱⢀⡾⣧⣭⣿⣆⢁⠐⡜⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⢧⠃⠄⠄⠄⠄⠇⢿⣿⣿⣿⡟⡸⠄⠄⠄⠄⠸⠿⡉⢹⣿⣿⡿⠸⠄⠐⠹⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡿⠈⠄⠄⠄⠄⠄⠈⠢⢉⣛⡩⠔⠁⢀⠄⠄⠄⣠⡄⠄⠄⡑⠉⠐⠁⠄⠄⡇⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡇⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠑⢴⣚⣿⣿⣖⡖⠁⠄⠄⠄⠄⠄⢠⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡇⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⡟⠛⠛⢿⠃⠄⠄⠄⠄⠄⠄⠘⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠒⠒⠄⠄⠄⠄⠄⠄⠄⠄⡆⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡏⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⢰⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⢟⣡⠄⠄⠄⠄⠄⠄⠄⠂⢀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠒⢝⢿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠑⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠃⠄⠄⢢⢻⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠰⢀⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠇⠄⠄⢀⢺⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠑⠂⠠⢄⠄⠄⠄⠄⠄⢀⠔⠁⠄⠄⣠⢊⣾⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⣿⠃⠄⠄⠄⠄⠄⠄⠄⠈⠐⠒⠢⠤⠤⠤⠄⠄⠂⠄⠄⠄⠄⠣⠤⠒⠂⠁⠄⢜⢿⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⡟⠄⠄⠄⠄⠄⠄⠄⠄⠈⠁⠂⢄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⡜⣿⣿⣿⣿⣿
//⣿⣿⣿⣌⢳⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢢⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡺⠆⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⡄⢿⣿⣿⣿⣿
//⣿⣿⣿⡇⡇⣮⠢⣠⡶⢶⡀⠄⠄⠄⠄⠄⠠⠴⠄⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠐⢝⢿⣿⣿
//⣿⣿⣿⣧⢧⣉⣾⡋⠥⢺⣧⠄⣀⡀⠄⠄⠄⠄⠄⠈⠳⡀⠤⠤⠤⣀⣒⣬⣭⣤⣀⣀⣒⣂⡠⠤⠤⣸⣿⣿
//⣿⣿⣿⣿⣿⣷⣬⣙⣛⠶⢟⣼⣷⣶⣶⣮⣭⣥⣖⣒⣒⣵⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿


Comments

Submit
0 Comments
More Questions

896A - Nephren gives a riddle
761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme
1195A - Drinks Choosing
5D - Follow Traffic Rules
1272A - Three Friends
1632D - New Year Concert
1400D - Zigzags
716C - Plus and Square Root
412A - Poster
844B - Rectangles
1591A - Life of a Flower
1398C - Good Subarrays
629A - Far Relative’s Birthday Cake
1166A - Silent Classroom
1000B - Light It Up
218B - Airport
1463B - Find The Array
1538C - Number of Pairs
621B - Wet Shark and Bishops
476B - Dreamoon and WiFi
152C - Pocket Book
1681D - Required Length
1725D - Deducing Sortability